<?php
/**
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* 
* @copyright Copyright (c) 2008-2009 Ne8, LLC <josh.ribakoff@gmail.com>
* @license New BSD License
* @version 0.1
* @category Shuffler 
* @package Shuffler_Db 
*/
class Shuffler_Db_Factory
{
    protected $db;
    protected $mappers = array();
    
    public function __construct( Shuffler_Db $db = null )
    {
        $this->db = isset( $db ) ? $db : Zend_Registry::get( 'db' );    
    }
    
    public function createTable( $name )
    {
        return new Shuffler_Db_Table( $this, $name );
    }
    
    public function getInflector()
    {
        if( isset( $this->inflector ) ) return $this->inflector;
        $this->inflector = new Shuffler_Db_Inflector();
        return $this->inflector;
    }
    
    public function getReadAdapter()
    {
        return $this->db;
    }
    
    public function getWriteAdapter()
    {
        return $this->db;
    }
    
    public function execute( $sql )
    {
        $r = mysql_query( $sql );
        if( !$r )
        {
            throw new Exception( $sql . ' : ' . mysql_error() );
        }
        return $r;
    }
    
    
}